#include <bits/stdc++.h>

using namespace std;

class Solution {
 public:
  long long sumDigitDifferences(vector<int>& nums) {
    int n = nums.size();
    // 第i位， 数字0~9
    vector<vector<int>> cnt;
    while (nums[0] > 0) {
      vector<int> tmp(10, 0);
      for (int j = 0; j < n; j++) {
        tmp[nums[j] % 10]++;
        nums[j] /= 10;
      }
      cnt.push_back(tmp);
    }
    for (int i = 0; i < 10; i++) {
      cout << i << " ";
    }
    cout << endl;
    for (int i = 0; i < cnt.size(); i++) {
      for (int j = 0; j < 10; j++) {
        cout << cnt[i][j] << " ";
      }
      cout << endl;
    }
    long long ans = 0;
    for (auto arr : cnt) {
      for (int i = 0; i < 10; i++) {
        ans = ans + (arr[i] == 0 ? 0 : arr[i] * (n - arr[i]));
      }
    }
    return ans / 2;
  }
};

int main(int argc, const char** argv) {
  Solution solution = Solution();
  vector<int> nums = {824, 843, 837, 620, 836, 234, 276, 859};
  long long res = solution.sumDigitDifferences(nums);
  std::cout << res << std::endl;
  return 0;
}